<?php
/**
 * Created by PhpStorm.
 * User: 咔咔
 * Date: 2020/9/21
 * Time: 11:35
 */

namespace container;

class RegistrationTree
{
    /**
     * 注册树池子
     * @var null
     */
    protected static $objects = null;

    /**
     * author:咔咔
     * 把对象挂到树上
     * @param $key
     * @param $object
     */
    public static function set ($key,$object)
    {
        self::$objects[$key] = $object;
    }

    /**
     * author:咔咔
     * 从树上获取对象  如果没有则注册
     * @param $key
     * @return mixed
     */
    public static function get ($key)
    {
        if(!isset(self::$objects[$key])){
            self::$objects[$key] = new $key;
        }

        return self::$objects[$key];
    }

    /**
     * author:咔咔
     * 从树上卸载对应对象
     * @param $key
     */
    public static function _unset ($key)
    {
        unset(self::$objects[$key]);
    }
}